import request from "@/axios"
import { ResponseData } from "../../../../constants"
import { SaveRole } from "./type"

enum Api {
  role = "/role/all",
  roleMenu = "/role/menu",
  saveRole = "/role/add",
  saveRolePermission = "/role/permission/save",
  rolePermission = "/role/permission",
  updateRole = "/role/update",
  removeRole = "/role/remove",
}

export const roleApi = {

  getRolePermissionApi: (roleId: string) => {
    return request.get<ResponseData>(Api.rolePermission, { roleId })
  },

  getRoleApi: (params: any) => {
    return request.get<ResponseData>(Api.role, params)
  },

  getRoleMenuApi: (roleIds: any) => {
    return request.get<ResponseData>(Api.roleMenu, { roleIds })
  },

  saveRoleApi: (role: SaveRole) => {
    return request.post<ResponseData>(Api.saveRole, role)
  },

  saveRolePermissionApi: (roleId: string, permissionList: string[]) => {
    return request.post<ResponseData>(Api.saveRolePermission, { roleId, permissionList })
  },

  updateRoleApi: (role: SaveRole) => {
    return request.post<ResponseData>(Api.updateRole, role)
  },

  removeRoleApi: (id: string) => {
    return request.get<ResponseData>(Api.removeRole, { id })
  }
}